#!/bin/sh

# compares with lurette the results of:
#   lv6 -exec -en
#   lv6 -2c-exec


lustre_file=$1
shift
OPT=$@


node=`basename $lustre_file .lus`
_oracle=_"$node"_oracle.lus
oracle="$node"_oracle
lv4="$node"_lv4.lus
ec="$node".ec
lv4_node="$node__$node"
env=_"$node"_env.lut
env_node="$node"_env
tmpdir=/tmp/lustre-test-ch-$node
tmpdir2=/tmp/lustre-test-cs-$node

. /home/jahier/.opam/opam-init/variables.sh
set -x verbose #echo on


# Compares
#   lv6 -2c-ioa
# versus
#   lv6 -2c-ioc
# XXX il y a -2c-ioah aussi ! et puis -2cgc
if
    [ -f $env_node ];
then
   echo "$env_node generated"

else if
    ./lus2lic $OPT $lustre_file -n $node --gen-autotest -np &&
    ./lus2lic $OPT $lustre_file -n $node -np -lic -o $lustre_file.lic &&
    cat $lustre_file.lic  >> $_oracle;

then
     echo "./lus2lic $OPT $lustre_file -n $node --gen-autotest -np: ok"
else
    echo "Error"
    exit 2
fi
fi

if
    ./lus2lic -dir $tmpdir $OPT $lustre_file -n $node  -2c-ioc -cc -o ${node}_ch.exec;
then
    echo "lus2lic -dir $tmpdir $OPT $lustre_file -n $node  -2c-ioc -cc -o ${node}_ch.exec:  done"
else
    echo "lus2lic -dir $tmpdir $OPT $lustre_file -n $node  -2c-ioc -cc -o ${node}_ch.exec: Error"
    exit 2
fi

if
    ./lus2lic -dir $tmpdir2 -en $OPT $_oracle -n $oracle -2c-ioa -cc -o ${oracle}_cs.exec;
then
    echo "lus2lic -dir $tmpdir2 -en $OPT $_oracle -n $oracle -2c-ioa -cc -o ${oracle}_cs.exec: done"
else
    echo "lus2lic -dir $tmpdir2 -en $OPT $_oracle -n $oracle -2c-ioa -cc -o ${oracle}_cs.exec: Error"
    exit 2
fi


PRECISION=4
if
    lurette -l 10   \
        -sut "./${node}_ch.exec" \
        -env "lutin $env -n $env_node -p $PRECISION -seed 42" \
        -oracle "./${oracle}_cs.exec";
then
    echo "Comparison of gcc and clang with lurette on $lustre_file: ok"
    echo "lurette ok"
else
    echo "error"
     exit 2
fi
exit 0
